class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
        int count = 0;
        sort(intervals.begin(), intervals.end());
        int m = intervals.size();
        for (int i = 1; i < m; i++)
        {
            if (intervals[i][0] < intervals[i - 1][1])
            {
                count++;
                intervals[i][1] = min(intervals[i][1], intervals[i - 1][1]);
            }
            else
            {
            }







        }
        return count;







    }
}; class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        int m = points.size();
        sort(points.begin(), points.end());
        int count = 1;
        for (int i = 1; i < m; i++)
        {
            if (points[i - 1][1] < points[i][0])
            {
                count++;
            }
            else
            {
                points[i][1] = min(points[i][1], points[i - 1][1]);

            }

        }
        return count;










    }
}; class Solution {
public:
    int longestPalindrome(string s) {
        int ret = 0;
        int hash[127] = { 0 };
        for (char c : s)
        {
            hash[c]++;
        }

        for (int x : hash)
        {
            ret += x / 2 * 2;
        }


        return ret < s.size() ? ret + 1 : ret;






    }
}; class Solution {
public:
    int longestPalindrome(string s) {
        int ret = 0;
        int hash[127] = { 0 };
        for (char c : s)
        {
            hash[c]++;
        }

        for (int x : hash)
        {
            ret += x / 2 * 2;
        }


        return ret < s.size() ? ret + 1 : ret;






    }
}; class Solution {
public:
    vector<int> diStringMatch(string s) {
        int left = 0;
        int right = s.size();
        vector<int>ret;
        vector<int>result;
        for (int i = left; i <= right; i++)
        {
            ret.push_back(i);
        }
        for (char c : s)
        {

            if (c == 'I')
            {
                result.push_back(ret[left++]);
            }
            else
            {
                result.push_back(ret[right--]);
            }
        }
        result.push_back(ret[left]);
        return result;











    }
}; class Solution {
public:
    int brokenCalc(int startValue, int target) {
        int cnt = 0;
        while (target > startValue)
        {
            if (target % 2 == 0)target /= 2;
            else target += 1;
            cnt++;
        }
        return cnt += startValue - target;







    }
}; class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int permin = INT_MAX;
        int maxProfit = 0;
        for (int i = 0; i < prices.size() - 1; i++)
        {
            permin = min(permin, prices[i]);
            maxProfit = max(prices[i + 1] - permin, maxProfit);
        }
        return  maxProfit;






    }
}; class Solution {
public:
    vector<int> rearrangeBarcodes(vector<int>& barcodes) {
        unordered_map<int, int>st;
        int maxval = 0;
        int maxcount = 0;
        for (auto e : barcodes)
        {
            if (maxcount < ++st[e])
            {
                maxcount = st[e];
                maxval = e;
            }
        }
        int n = barcodes.size();


        vector<int>ret(n);
        int index = 0;
        for (int i = 0; i < maxcount; i++)
        {
            ret[index] = maxval;
            index += 2;
        }
        st.erase(maxval);
        for (auto& [a, b] : st)
        {

            for (int i = 0; i < b; i++)
            {
                if (index >= n)
                    index = 1;
                ret[index] = a;
                index += 2;
            }
        }

        return ret;









    }
};